<script>
  // #1
  Promise.resolve().then(() => {
    // #2
    Promise.resolve().then(r => {
      // #3
      console.log(8);
      // return Promise.resolve(undefined)
    }).then(r => {
      // #5
      console.log(9);
    }).then(r => {
      // #7
      console.log(1);
    });
    // return Promise.resolve(undefined)
  }).then(r => {
    // #4
    console.log(2);
    // return Promise.resolve(undefined)
  }).then(() => {
    // #6
    console.log(4)
  });
</script>